package com.stox.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.stox.dto.enumeration.SpanType;
import com.stox.dto.web.Response;
import com.stox.manager.BarManager;
import com.stox.model.Bar;

@RestController
@RequestMapping(value="/bars")
public class BarController {

	@Autowired
	private BarManager barManager;
	
	@ResponseBody
	@RequestMapping(method=RequestMethod.GET, produces="application/json")
	public Response<List<Bar>> findByScripCode(@RequestParam("scripId") Long scripId) {
		return new Response<>(barManager.findByScripId(scripId));
	}
	
	@ResponseBody
	@RequestMapping(method=RequestMethod.GET, produces="application/json", params={"scripId","spanType","start","count"})
	public Response<List<Bar>> findByScripId(@RequestParam Long scripId, @RequestParam SpanType spanType, @RequestParam Long start,@RequestParam  int count){
		return new Response<List<Bar>>(barManager.findByScripId(scripId, spanType, new Date(start), count));
	}
	
	@ResponseBody
	@RequestMapping(method=RequestMethod.GET, produces="application/json", params={"scripId","spanType","start","end"})
	public Response<List<Bar>> findByScripId(@RequestParam Long scripId, @RequestParam SpanType spanType, @RequestParam Long start,@RequestParam  Long end){
		return new Response<List<Bar>>(barManager.findByScripId(scripId, spanType, new Date(start), new Date(end)));
	}
}
